<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../../css/index.css" />
<link rel="stylesheet" type="text/css" href="../../jeasyui/themes/gray/easyui.css" />
<link rel="stylesheet" type="text/css" href="../../jeasyui/themes/icon.css" />
<link rel="stylesheet" href="../../kindeditor/themes/simple/simple.css" />

<script type="text/javascript" src="../../kindeditor/kindeditor.js"></script>
<script type="text/javascript" src="../../kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="../../jeasyui/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../jeasyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../jeasyui/locale/easyui-lang-zh_CN.js"></script>
<title>主页</title>
<style type="text/css">
</style>
<script type="text/javascript">
	
	var editor;

	var items = [
	             'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 
	             'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
	             'justifyfull', 'insertorderedlist', 'insertunorderedlist',  'indent', 'outdent', '/',
	             'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|',  
	             'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
	             'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
	             'flash','/', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
	             'anchor', 'link', 'unlink', 
	     ];
	
	KindEditor.ready(function(K) {
	    editor = K.create('#editor_id', {
				   resizeType : 1,  
				   minWidth : '500px',
				   height : '400px',
				   items : items
    			 });
	});

	function updateArticle(){
		var title = $("#title").val();
		if(title==""){
			$.messager.alert('提示',getMessage('请输入标题！'),'info');
			return;
		}
		var categoryId = $('#articleCategory').combobox("getValue");
		var content = editor.html();
		var id = $("#articleId").val();
		
		$.post( "article.do?method=updateArticle",
				{ 'id':id,
				  'title':title,
				  'content':content,
				  "articleCategory.id" : categoryId}, 
				function(data){
					  if(data == "success"){
						  window.location.href="myArticles.jsp";
					  } else {
						  $.messager.alert('提示',getMessage(data),'info');
					  }
				}
		);
	}
	
	function initArticleCategory(){
	    $('#articleCategory').combobox({
	        url:'article.do?method=listArticleCategorys',
	        valueField: 'id',
	        textField: 'name',
	        panelHeight:'auto',
	        onLoadSuccess :function(){
	        	$('#articleCategory').combobox("select", '${article.articleCategory.id}');
	        }
        });
	}
	
	$(function(){
		initArticleCategory();
	});
</script>
</head>

<body>
<!-- wrap starts here -->
<div id="wrap">
		
		<!--header -->
		<div id="header">			
				
			<h1 id="logo-text"><a href="#">Siloam</a></h1>		
			<p id="slogan">Here am I. Send me!</p>		
			
			<div id="header-links">
			<p>
				<a href="index.html">后台</a> | 
				<a href="index.html">退出</a>			
			</p>		
		</div>		
						
		</div>
		
		<!-- menu -->	
		<div  id="menu">
			<ul>
				<li ><a href="#">首页</a></li>
				<li><a href="#">团契介绍</a></li>
				<li><a href="#">联系我们</a></li>
				<li id="current"><a href="#">个人中心</a></li>
			</ul>
		</div>					
			
		<!-- content-wrap starts here -->
		<div id="content-wrap">
				
			<div id="sidebar">
			
				<h3>功能列表</h3>
				<ul class="sidemenu">				
					<li><a href="#">团契动态</a></li>
					<li><a href="#">我的代祷</a></li>
					<li><a href="#">我的文章</a></li>
					<li><a href="#">我的小组</a></li>
					<li><a href="#" title="Web Templates">密码修改</a></li>
				</ul>
								
			</div>
				
			<div id="main">
				<h2>写文章</h2>
				<input type="hidden" value="${article.id}" id="articleId"/>
				<label>类型</label>
				<select class="easyui-combobox" id="articleCategory" style="width: 200px"></select>
				<label>标题</label>
				<input type="text" id="title" style="width: 99%; border: 1px solid #DDD;" value="${article.title}"/>
				<label>正文</label>
				<textarea id="editor_id" name="content" style="width: 100%">${article.content}</textarea>
				<div style="padding: 10px 0;text-align: right;">
					<a href="myArticles.jsp">取消</a>&nbsp;&nbsp;
					<input class="button" type="button" value="修改" onclick="updateArticle()"/>
				</div>
			</div>
		
		<!-- content-wrap ends here -->	
		</div>
					
		<!--footer starts here-->
		<div id="footer">
            <p>&copy; 2013 <strong>copyright siloam</strong>
   	    </p>
				
		</div>	

<!-- wrap ends here -->
</div>

</body>
</html>
